﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebStudio.Business.Rule;

public partial class Admin_ProductMge : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Admin_User"] == null || Session["Admin_User"].ToString() == "")
        {
            Response.Redirect("~/Admin/Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            InitPage();
        }
    }

    private void InitPage()
    {
        //ddlParentNavBind();
        anpList.PageSize = 15;
        anpList.CurrentPageIndex = 1;
        anpList.RecordCount = PhotoRule.GetPhotoListCount();
        rptArticleBind();
    }

    private void rptArticleBind()
    {
        rptArticle.DataSource = PhotoRule.GetPhotoList(anpList.CurrentPageIndex, anpList.PageSize, anpList.PageCount, anpList.RecordCount);
        rptArticle.DataBind();
    }

    protected void rptArticle_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            LinkButton lbtnDelete = e.Item.FindControl("lbtnDelete") as LinkButton;
            PhotoRule.DeletePhotoInfor(Convert.ToInt32(lbtnDelete.CommandArgument));
            rptArticleBind();
        }
    }

    protected void anpList_PageChanged(object sender, EventArgs e)
    {
        rptArticleBind();
    }

    //private void ddlParentNavBind()
    //{
    //    //ddlParentNav.DataSource = bCategory.GetParentList();
    //    ddlParentNav.DataSource = CategoryRule.GetParentCategoryList(2);
    //    ddlParentNav.DataTextField = "CategoryName";
    //    ddlParentNav.DataValueField = "CategoryId";
    //    ddlParentNav.DataBind();
    //    ddlParentNav.Items.Insert(0, new ListItem("请选择...", "0"));
    //    ddlSubNav.Items.Insert(0, new ListItem("请选择...", "0"));
    //}
    //private void ddlSubNavBind(int id)
    //{
    //    ddlSubNav.DataSource = CategoryRule.GetParentCategoryList(id);
    //    ddlSubNav.DataTextField = "CategoryName";
    //    ddlSubNav.DataValueField = "CategoryId";
    //    ddlSubNav.DataBind();
    //}

    //protected void ddlParentNav_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    int id = Convert.ToInt32(ddlParentNav.SelectedValue);
    //    if (id != 0)
    //    {
    //        ddlSubNavBind(id);
    //    }
    //    else
    //    {
    //        ddlSubNav.Items.Clear();
    //    }
    //    ddlSubNav.Items.Insert(0, new ListItem("请选择...", "0"));
    //}
    //protected void btnSearch_Click(object sender, EventArgs e)
    //{
    //    anpList.PageSize = 15;
    //    anpList.CurrentPageIndex = 1;
    //    anpList.RecordCount = ArticalRule.GetArticalListCount(1, Convert.ToInt32(ddlSubNav.SelectedValue), Convert.ToInt32(ddlParentNav.SelectedValue), "2");
    //    rptArticleBind();
    //}
}
